<?php

// Get variables

$directories = v('concepts');
$richConcepts = v('richConcepts');
$extensionId = v('extensionId');


// Get the path to extension

$pathToExtension = app()->getPathHelper()->convertExtensionIdToPath($extensionId);

?>

<ul class="breadcrumb">
	<li>
		<a href="<?php p(url('[Loop]/page/admin/documentation')); ?>" >Documentation</a>
		<span class="divider">/</span>
	</li>
	<li class="active">
		<?php p($extensionId); ?>
	</li>
</ul>


<h4 style="text-align: center;">
	<?php p($extensionId); ?>
</h4>

<?php
	
	render
	(
		'[Loop]/Html/Snippet.RichDocumentation.html',
		array 
		(
			'extensionId' => $extensionId,
			'concept' => null,
			'file' => $extensionId,
			'method' => null
		)
	);

?>
<div class="tabbable">
	<ul class="nav nav-tabs" id="myTab">
		<?php
			$cpt = 0;

			// For each directory found, print it

			foreach ($directories as $directory) 
			{
		?>
				<li <?php if($cpt==0) { ?> class="active" <?php } ?>>
					<a href="#<?php p($directory); ?>" data-toggle="tab"><?php p($directory); ?></a>
				</li>
			<?php
				$cpt++;
			}

			foreach ($richConcepts as $richConcept) 
			{			
		?>
				<li>
					<a href="#<?php p($richConcept); ?>" data-toggle="tab"><?php p($richConcept); ?></a>
				</li>		
		<?php
			}
		?>
	</ul>
</div>


<div class="tab-content">
	<?php
		$cpt = 0;

		// For each directory found, print it

		foreach ($directories as $directory) 
		{
			$files = app()->getDocumentationManager()->getFiles($extensionId, $directory);
	?>
			<div class="tab-pane <?php if($cpt==0) { ?> active <?php } ?>" id="<?php p($directory); ?>">
			<?php

			// For each result

			foreach ($files as $typeFile => $fileNames)
			{
				// Sort the files

				ksort($fileNames);
			?>
				
				<h3><?php p($typeFile); ?></h3>
				<div>
					<table class="table table-hover table-bordered">
						<thead>
						    <tr>
						      <th>Name</th>
						      <th>Description</th>
						    </tr>
						</thead>
						<tbody>
									
						<?php

							foreach ($fileNames as $fileName => $description)
							{

						?>

							<tr>
								<td>
									<a href="<?php p(url('[Loop]/page/admin/documentation/concept/') . '?extensionId=' . $extensionId .'&directory=' . $directory . '&file=' . $fileName);?>">
										<?php p($fileName); ?>
									</a>
								</td>
								<td>
									<?php p($description); ?>
								</td>
							</tr>
						<?php

							}

						?>
						</tbody>
					</table>
				</div>
			<?php
			}
			?>				
			</div>
		<?php
			$cpt++;
		}

		foreach($richConcepts as $richConcept)
		{
	?>
			<div class="tab-pane" id="<?php p($richConcept); ?>">
			<?php
				
				render
				(
					'[Loop]/Html/Snippet.RichDocumentation.html',
					array 
					(
						'extensionId' => $extensionId,
						'concept' => $richConcept,
						'file' => $richConcept,
						'method' => null
					)
				);

			?>				
			</div>
	<?php

		}
	?>
</div>
